//
//  AuthenViewController.swift
//  cxd4iphone
//
//  Created by hexy on 12/26/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit

private struct kConstraints {
    
    static let headerHeight: CGFloat = xx_screenHeight() - 64
    static let headerRect: CGRect    = CGRectMake(0, 0, xx_screenWidth(), kConstraints.headerHeight)
    static let footerHeight: CGFloat = xx_screenHeight() - kConstraints.headerHeight - 64 - 49
    static let footerRect: CGRect    = CGRectMake(0, 0, xx_screenWidth(), kConstraints.footerHeight)
}


class AuthenViewController: BaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    
    override func makeTableView() {
        
        tableView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "tap"))
        
        tableView.tableHeaderView = authenView
        
        authenView.submitBtn.rac_signalForControlEvents(.TouchUpInside).subscribeNext { (_) -> Void in
            self.view.endEditing(true)
            
            xx_print(self.authenView.realNameTextField.text)
            xx_print(self.authenView.idCardTextField.text)
            
            guard let realName = self.authenView.realNameTextField.text else { return }
            guard let idCard = self.authenView.idCardTextField.text else { return }
            
            YPRequestViewModel.shared.authentication(realName, idCard: idCard).subscribeError({ (error) -> Void in
                
                    xx_showError(error)
                }, completed: { () -> Void in
                    
                    let vc = WebViewController(title: "实名认证", htmlStr: YPRequestViewModel.shared.html)
                    self.navigationController?.pushViewController(vc, animated: true)
            })
        }
    }
    func tap() {
        
        self.view.endEditing(true)
    }
    lazy var authenView = AuthenView(frame: kConstraints.headerRect)
    
}
